package com.tfj.comm.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.hyphenate.tfj.R;
import com.tfj.mvp.tfj.home.bean.AdBean;
import com.tfj.mvp.tfj.per.VPerFragment;

import androidx.fragment.app.Fragment;

@SuppressLint("ValidFragment")
public class BannerFragmentRound extends Fragment {

    private static final String RES_ID = "resId";
    private static final String POSITION = "position";
     private Context context =null;
     private int positon =0 ;
     private AdBean.DataBean bean =null;
     private boolean ifRoundAngel = false;
    public BannerFragmentRound(AdBean.DataBean bean, int position, Context context,boolean ifRoundAngel) {
        this.context = context;
        this.bean = bean;
        this.ifRoundAngel = ifRoundAngel;
        this.context = context;
    }

    public static BannerFragmentRound newInstance(AdBean.DataBean bean, int position,Context context,boolean ifRoundAngel) {
        BannerFragmentRound fragment = new BannerFragmentRound(bean,position,context,ifRoundAngel);
        return fragment;
    }
    public void LoadImageUrl(ImageView id, String imageurl) {
        RequestOptions options = new RequestOptions();
        options.placeholder(R.mipmap.ic_launcher);
        options.error(R.mipmap.ic_launcher);
        options.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        options.dontAnimate();
        Glide.with(this).load(imageurl).thumbnail(0.9f).apply(options).into(id);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(this.ifRoundAngel?R.layout.fragment_banner_round:R.layout.fragment_banner, container, false);
        ImageView imageView = rootView.findViewById(R.id.imageView);
        if (!TextUtils.isEmpty(bean.getImg())) {
            LoadImageUrl(imageView,bean.getImg());
        }else{
            imageView.setImageResource(R.drawable.splash);
        }
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        return rootView;
    }
}
